package cc.yugu.yhdw.webserver.web.controller.security.basic;


import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.domain.AreaEntity;
import cc.yugu.yhdw.common.domain.basic.AddressBook;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.json.PageResult;
import cc.yugu.yhdw.webserver.service.basic.AddressBookService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 地址簿控制类
 * 
 * @Date:Created in 2018/7/11 15:13
 * @Author:
 * @Modified By: zjn 2018/7/11 15:13
 */ 
@Controller
@RequestMapping(value = "/security/basic/address_book")
public class AddressBookController extends SecurityController {

    @Autowired
    AddressBookService addressBookService;
    /**
    * 地址簿分页查询
    * 
    * @Param: [addressBook]
    * @Return: cc.yugu.yhdw.common.entity.json.PageResult
    * @Author By: zjn 2018/7/11  15:16
    */ 
    @RequestMapping(value = "page.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public PageResult page(AddressBook addressBook) {
        return PageResult.successResult(addressBookService.findPage(addressBook));
    }
    /**
    * 返回客户id
    * 
    * @Param: [passportId, model]
    * @Return: void
    * @Author By: zjn 2018/7/11  17:03
    */ 
    @RequestMapping("add.htm")
    public void add(Integer passportId, Model model) {
        model.addAttribute("passportId", passportId);
    }
    /**
    * 返回查询地址到edit.htm显示
    *
    * @Param: [id, model]
    * @Return: void
    * @Author By: zjn 2018/7/11  17:03
    */
    @RequestMapping(value = "edit.htm")
    public void edit(int id, Model model) {
        // 查询地址
        AreaEntity smsConfig = addressBookService.find(id);
        model.addAttribute("entity", smsConfig);
    }
    /**
    * 返回地址到view.htm显示
    *
    * @Param: [id, model]
    * @Return: void
    * @Author By: zjn 2018/7/11  17:04
    */
    @RequestMapping(value = "view.htm")
    public void view(int id, Model model) {
        AreaEntity smsConfig = addressBookService.find(id);
        model.addAttribute("entity", smsConfig);
    }
    /**
    * 插入数据，前台获取显示
    *
    * @Param: [addressBook]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/11  17:05
    */
    @ResponseBody
    @ViewModel(ViewModel.JSON)
    @RequestMapping(value = "create.htm")
    public ExtResult create(AddressBook addressBook) {
        // 插入数据到地址簿数据库
        return addressBookService.insert(addressBook);
    }
    /**
    * 更新
    * 
    * @Param: [addressBook]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/11  17:09
    */ 
    @ResponseBody
    @ViewModel(ViewModel.JSON)
    @RequestMapping(value = "update.htm")
    public ExtResult update(AddressBook addressBook) {
        return addressBookService.update(addressBook);
    }
    /**
    * 删除
    * 
    * @Param: [id]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/11  17:09
    */ 
    @RequestMapping("delete.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult delete(int id) {
        return addressBookService.delete(id);
    }
}
